package com.myapp.struts.action;

import com.myapp.hibernate.model.Boxeador;
import com.myapp.hibernate.model.Combate;
import com.myapp.hibernate.model.MuestraCombate;
import com.myapp.hibernate.util.BoxeadorUtil;
import com.myapp.hibernate.util.CombateUtil;
import com.myapp.hibernate.util.EstadioUtil;
import com.myapp.struts.form.CombatesForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class VerEntradaAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        CombatesForm formulario = (CombatesForm) form;
        CombateUtil combateUtil = new CombateUtil();
        BoxeadorUtil boxeadorUtil = new BoxeadorUtil();
        EstadioUtil estadioUtil = new EstadioUtil();

        Combate c = combateUtil.obtenerCombate(formulario.getIdCombate());
        MuestraCombate mc = new MuestraCombate();
        Boxeador boxeadorAuxiliar = boxeadorUtil.obtenerBoxeador(c.getIdBoxeador1());
        mc.setNombreBoxeador1(boxeadorAuxiliar.getNombre() + " " + boxeadorAuxiliar.getApellidos());
        boxeadorAuxiliar = boxeadorUtil.obtenerBoxeador(c.getIdBoxeador2());
        mc.setNombreBoxeador2(boxeadorAuxiliar.getNombre() + " " + boxeadorAuxiliar.getApellidos());
        mc.setEstadio(estadioUtil.obtenerEstadio(c.getIdEstadio()).getNombre());
        mc.setFecha(c.getFecha());
        mc.setIdCombate(c.getIdCombate());
        mc.setPrecioEntrada(c.getPrecioEntrada());
        formulario.setCombate(mc);



        return mapping.findForward(SUCCESS);
    }
}
